package cn.codeforfun.base;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangbin
 */
public class BaseController<E extends BaseEntity, S extends BaseService<E, ? extends BaseRepository<E>>> {

    public S service;

    public BaseController(S service) {
        this.service = service;
    }

    @GetMapping
    public Page<E> listPage(Pageable pageable) {
        return service.listPage(pageable);
    }

    @GetMapping("/{id}")
    public E getById(@PathVariable String id) {
        return service.getById(id);
    }

    @PostMapping
    public void save(@RequestBody E e) {
        service.save(e);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable String id) {
        service.deleteById(id);
    }
}
